package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.OrderGas;
import com.sc.nft.mapper.OrderGasMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

/**
 * @author 刘国航
 * @desc
 * @since 2024/10/21 11:11
 */
@Slf4j
@Repository
public class OrderGasDao extends ServiceImpl<OrderGasMapper, OrderGas> {

    public Boolean addGasPool(BigDecimal gas) {
        LambdaUpdateWrapper<OrderGas> wrapper = new LambdaUpdateWrapper<>();
        wrapper.setSql("gas_pool = gas_pool + " + gas);
        return update(wrapper);
    }

    public Boolean addReceiveRewards(BigDecimal gasReceiveTotal, BigDecimal gasRewardsTotal) {
        LambdaUpdateWrapper<OrderGas> wrapper = new LambdaUpdateWrapper<>();
        wrapper.setSql("gas_receive_total = gas_receive_total + " + gasReceiveTotal);
        wrapper.setSql("gas_rewards_total = gas_rewards_total + " + gasRewardsTotal);
        wrapper.setSql("gas_pool = gas_pool - " + gasReceiveTotal);
        wrapper.ge(OrderGas::getGasPool, gasReceiveTotal);
        return update(wrapper);
    }

}
